﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Event_cal : System.Web.UI.Page
{
    DataView Event_todo = new DataView();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Calendar1.SelectedDate == DateTime.MinValue)
            Calendar1.SelectedDate = Calendar1.TodaysDate;

    }
    void Page_PreRender()
    {
        Event_todo = (DataView)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
        Event_todo.Sort = "Event_date";
       
    }
    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        e.Cell.VerticalAlign = VerticalAlign.Top;
        if (Event_todo.FindRows(e.Day.Date).Length > 0)
       {
           e.Cell.BackColor = System.Drawing.Color.Yellow;
        
           foreach(DataRowView drv in Event_todo){
                 
                    if(e.Day.Date == Convert.ToDateTime(drv["Event_date"]))
                        e.Cell.Controls.Add(new LiteralControl(Convert.ToString(drv["Event_todo"])));
                }
       }

    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        FormView1.ChangeMode(FormViewMode.Edit);

    }
    protected void butAddNew_Click(object sender, EventArgs e)
    {
        FormView1.ChangeMode(FormViewMode.Insert);
    }
    protected void butCancel_Click(object sender, EventArgs e)
    {
        FormView1.ChangeMode(FormViewMode.Edit);
    }
}

